﻿using System.Configuration;
using System.Diagnostics;

namespace MvcShop.MVC.Handlers.Resources
{
    /// <summary>
    /// 配置节操作
    /// </summary>
    public class ResourcesElementCollection:ConfigurationElementCollection
    {
        public new ResourcesElement this[string name]
        {
            [DebuggerStepThrough]
            get
            {
                return BaseGet(name) as ResourcesElement;
            }
        }

        public void Add(ResourcesElement element)
        {
            BaseAdd(element);
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ResourcesElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ResourcesElement)element).Name;
        }
    }
    /// <summary>
    /// 资源管理配置节子节点
    /// </summary>
    public class ResourcesElement:ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            [DebuggerStepThrough]
            get { return (string)this["name"]; }
            [DebuggerStepThrough]
            set { this["name"] = value; }
        }

        [ConfigurationProperty("contentType", IsRequired = true)]
        public string ContentType
        {
            [DebuggerStepThrough]
            get { return (string)this["contentType"]; }
            [DebuggerStepThrough]
            set { this["contentType"] = value; }
        }

        [ConfigurationProperty("compress", DefaultValue = ResourcesSettingsSection.DefaultCompress)]
        public bool Compress
        {
            [DebuggerStepThrough]
            get { return (bool)this["compress"]; }
            [DebuggerStepThrough]
            set { this["compress"] = value; }
        }

        [ConfigurationProperty("generateETag", DefaultValue = ResourcesSettingsSection.DefaultGenerateETag)]
        public bool GenerateETag
        {
            [DebuggerStepThrough]
            get { return (bool)this["generateETag"]; }
            [DebuggerStepThrough]
            set { this["generateETag"] = value; }
        }

        [ConfigurationProperty("version")]
        public string Version
        {
            [DebuggerStepThrough]
            get { return (string)this["version"]; }
            [DebuggerStepThrough]
            set { this["version"] = value; }
        }

        [ConfigurationProperty("cacheDurationInDays", DefaultValue = ResourcesSettingsSection.DefaultCacheDurationInDays)]
        public float CacheDurationInDays
        {
            [DebuggerStepThrough]
            get { return (float)this["cacheDurationInDays"]; }
            [DebuggerStepThrough]
            set { this["cacheDurationInDays"] = value; }
        }

        [ConfigurationProperty("directory", IsRequired = true)]
        public string Directory
        {
            [DebuggerStepThrough]
            get { return (string)this["directory"]; }
            [DebuggerStepThrough]
            set { this["directory"] = value; }
        }

        [ConfigurationProperty("files", IsRequired = true)]
        public string Files
        {
            [DebuggerStepThrough]
            get { return (string)this["files"]; }
            [DebuggerStepThrough]
            set { this["files"] = value; }
        }
    }
}
